//
// Created by zhou on 2021/10/19.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution{
public:
    int maxSub(vector<int>& nums){
       int size=nums.size();
       int first=nums[0];
       int res=first;
       if(size==1)return first;
       for(int i=1;i<size;i++){
           int tmp=max(first+nums[i],nums[i]);
           first=tmp;
           if(first>res)res=first;
       }
       return res;
    }
};
int main(){
    Solution solution;
    vector<int> nums={1,-1,3,-2,1,24,5,-23,4};
    cout<<solution.maxSub(nums);
}
